package com.axonactive.yolo.webservice;

import java.io.IOException;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;

import com.axonactive.yolo.webservice.utils.Utils;

@Path("/password")
public class Password {
	// The @Context annotation allows us to have certain contextual objects
	// injected into this class.
	// UriInfo object allows us to get URI information (no kidding).
	@Context
	UriInfo uriInfo;

	// Another "injected" object. This allows us to use the information that's
	// part of any incoming request.
	// We could, for example, get header information, or the requestor's
	// address.
	@Context
	Request request;

	// Use data from the client source to create a new Person object, returned
	// in JSON format.
	/**
	 * @param forgotPasswordParam
	 *            ' KEY: forgotPasswordParam VALUE:
	 *            {"userEmail":"email@gmail.com"}
	 * @return jsonObj
	 * @throws IOException
	 * @throws InterruptedException
	 */
	@POST
	@Path("/forgot")
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	@Produces(MediaType.APPLICATION_JSON)
	public String forgotPassword(
			MultivaluedMap<String, String> forgotPasswordParam)
			throws IOException, InterruptedException {
		return Utils.call("forgot_password/"
				+ forgotPasswordParam.getFirst("forgotPasswordParam"));
	}

	/**
	 * @param changePasswordParam
	 *            KEY: forgotPasswordParam VALUE:
	 *            {"userId":123,"currentPassword":"password_encrypted",
	 *            "newPassword":"password_encrypted",
	 *            "confirmPassword":"password_encrypted"}
	 * @return
	 * @throws IOException
	 * @throws InterruptedException
	 */
	@POST
	@Path("/change")
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	@Produces(MediaType.APPLICATION_JSON)
	public String resetPassword(
			MultivaluedMap<String, String> changePasswordParam)
			throws IOException, InterruptedException {
		return Utils.call("change_password/"
				+ changePasswordParam.getFirst("changePasswordParam"));
	}
}
